package com.yst.webplugin.api;

import com.yst.web.common.Result;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public interface ApiBuilderConfig {
    void config(List<EntityConfig> configList);

     default void registerEntities(List<ApiEntity> apiEntities){
         ApiEntity apiResultEntity=new ApiEntity()
                 .setDescription("result type")
                 .setClassName(Result.class.getName())
                 .setGeneric(Collections.singletonList("T"))
                 .setFieldList(
                         Arrays.asList(
                            new ApiField().setFieldName("code").setDescription("code for result").setFieldType("int"),
                                 new ApiField().setFieldName("data").setDescription("data for result").setFieldType("T"),
                                 new ApiField().setFieldName("msg").setDescription("error or warning message").setFieldType("string")
                         )
                 );
         ApiEntity apiListEntity=new ApiEntity()
                 .setDescription("array type")
                 .setClassName(List.class.getName())
                 .setFieldList(
                         Collections.singletonList(
                                 new ApiField().setFieldName("[]").setDescription("array data").setFieldType("T")
                         )
                 );
         apiEntities.add(apiResultEntity);
         apiEntities.add(apiListEntity);
     }
}
